package com.springcloud.ssoclientdemo.config

import org.springframework.cloud.client.loadbalancer.LoadBalanced
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.oauth2.client.OAuth2ClientContext
import org.springframework.security.oauth2.client.OAuth2RestTemplate
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails

@Configuration
class SsoConfig {

    /*
      使用OAuth2RestTemple发出的请求会携带以Token为值的Authorization请求头
   */
    @Bean
    @LoadBalanced
    OAuth2RestTemplate oAuth2RestTemplate(OAuth2ProtectedResourceDetails resourceDetails, OAuth2ClientContext context)
    {
        new OAuth2RestTemplate(resourceDetails,context)
    }

}
